package com.dao.impl;

import com.bean.Favorite;
import com.bean.FavoriteList;
import com.dao.BaseDao;
import com.dao.FavoriteDao;

import java.util.List;

public class FavoriteDaoImpl extends BaseDao implements FavoriteDao {
    //添加收藏
    @Override
    public int addFav(Favorite favorite) {
        String sql = "insert into `favorite` (userId,videoId) value (?,?)";
        return update(sql, favorite.getUserId(), favorite.getVideoId());
    }
//删除收藏
    @Override
    public int deleFav(int id) {
        String sql = "DELETE FROM `favorite`WHERE `id`=?";
        return update(sql, id);
    }

    @Override//收藏查询
    public List<FavoriteList> queryForFavType(Integer id) {
        String sql = "SELECT viedo.vname,viedo.pic,viedo.path,`user`.userName,favorite.id FROM viedo LEFT JOIN favorite ON viedo.id=favorite.videoId LEFT JOIN\n" +
                " `user` on favorite.userId=`user`.id WHERE favorite.userId=?";
        return queryForList(FavoriteList.class, sql, id);
    }

}
